package com.caishi.lkx.user.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caishi.lkx.user.model.MemberModel;
import com.caishi.lkx.user.model.OssUserModel;
import com.zzw.common.exception.BizException;
import com.zzw.common.service.NameService;
import com.caishi.lkx.user.dto.IndexMemberSearchVo;
import com.caishi.lkx.user.dto.RegisterMemberDto;
import com.caishi.lkx.user.dto.UserRecordsVo;
import com.caishi.lkx.user.ienum.type.UserChannelType;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * @author by keray
 * date:2021/4/9 10:53 上午
 */
public interface IMemberService extends IUserService<MemberModel>, NameService<MemberModel, String> {


    /**
     * <p>
     * <h3>作者 keray</h3>
     * <h3>时间： 2021/6/5 10:58 上午</h3>
     * 查询用户的学号
     * </p>
     *
     * @param memberId
     * @return <p> {@link String} </p>
     * @throws
     */
    String no(String memberId);


    void batchImportGroupMembers(List<MemberModel> memberModels, String defaultPass) throws BizException;

    String addGroupMember(MemberModel memberModel, String defaultPass) throws BizException;

    IPage<MemberModel> search(Map<String, Object> param, Page<MemberModel> page, boolean total);

    /**
     * @return void
     * @Param: [currentUserId, groupId]
     * @Author: huangpeng
     * @Date: 2022/2/9 16:46
     * @Description: 用户绑定/换绑机构
     */
    Boolean bindGroup(String currentUserId, Long groupId);

    /**
     * 后台机构用户绑定
     *
     * @param userId  用户 id
     * @param groupId 机构id
     * @return
     */
    Boolean bindBack(String userId, Long groupId, LocalDateTime expireTime);

    /**
     * 根据vers6 id 绑定机构
     *
     * @param memberModel
     * @param groupCode
     * @param
     * @return
     */
    Boolean bindGroupCode(MemberModel memberModel, String groupCode);

    /**
     * @return void
     * @Param: [currentUserId]
     * @Author: huangpeng
     * @Date: 2022/2/9 16:46
     * @Description: 用户机构解绑
     */
    Boolean unBindGroup(String currentUserId);

    /**
     * 更新用户机构认证时间
     *
     * @param currentUserId
     * @return
     */
    Boolean updateExpireDate(String currentUserId, Long localGroupId);

    Boolean updateExpireDate(String userId);

    Boolean importMember(MultipartFile file, Long groupId, UserChannelType channelType, String createdBy) throws IOException;

    Long currentGroupId(String currentUserId);

    /**
     * 绑定vers7 和考研
     *
     * @param currentUserId
     * @param groupId
     * @param expireTime
     * @return
     */
    Boolean bindVers7AndKaoyan(String currentUserId, Long groupId, LocalDateTime expireTime);

    /**
     * 获取考情数据
     *
     * @param categoryId 科目id
     * @param userId     用户id
     * @return
     */
    UserRecordsVo getUserRecordsByCategoryId(Long categoryId, String userId);

    /**
     * 机构新增加用户
     *
     * @param userId    用户id
     * @param memberDto 注册信息
     * @return
     */
    Boolean addMember(Long groupId, String userId, RegisterMemberDto memberDto) throws BizException;

    /**
     * 机构新增加用户
     *
     * @param userId    用户id
     * @param memberDto 注册信息
     * @return
     */
    Boolean addMemberForPc6(Long groupId, String userId, RegisterMemberDto memberDto) throws BizException;

    /**
     * 新增个人用户
     *
     * @param userId    用户id
     * @param memberDto 注册信息
     * @return
     */
    Boolean addMemberForYkt(String id, String userId, RegisterMemberDto memberDto) throws BizException;

    /**
     * 前台机构用户管理
     *
     * @param page     分页
     * @param searchVo 搜索条件
     * @return
     */
    IPage<IndexMemberSearchVo> searchIndex(Page<IndexMemberSearchVo> page, Map<String, Object> searchVo);

    /**
     * 机构管理者删除用户
     *
     * @param ids 用户id
     * @return
     */
    void deleteUser(List<String> ids, Long groupId);

    /**
     * 用户注销
     *
     * @param userId 用户id
     */
    void logoff(String userId) throws InterruptedException, TimeoutException;

    void updateMember(RegisterMemberDto registerMemberDto);

    //将用户信息发送给vers7
    Boolean sendVers6(String userId, String header, Boolean isSync);

    //解密vers发送过来的数据
    OssUserModel decryptionVers(String code);
    //解密重庆人社培训网数据
    OssUserModel decryptionCqrspx(String code);

    //加密数据
    String encryptionVers(OssUserModel ossUserModel);

    //获取vers 在当前的userId
    String getUserIdByssoUserModel(OssUserModel userModel);

    /**
     * 保存vers
     *
     * @param userModel
     * @param userId
     * @return
     */
    MemberModel saveVers6(OssUserModel userModel, String userId) throws BizException;
    /**
     * 保存人社培训网用户
     * */
    MemberModel saveCqrspx(OssUserModel userModel, String userId) throws BizException;
    /**
     * 拉取vers6的数据更改当前用户信息
     *
     * @param userAccount
     * @return
     */
    MemberModel fetchVersRegister(String userAccount) throws BizException;


    //按日期统计用户数
    List<Map> countLine(Map<String, Object> param);
}
